package View;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

/**
 * Frame for the map display screen
 */
public class MapFrame extends JFrame
{
    private MapPanel mapPanel;
    private CardLayout cardlayout;

    /**
     * Created the Jframe for displaying the map. This itself calls the constructor for this Frame's MapPanel.
     */
    public MapFrame()
    {
        setResizable(false);
        this.setBounds(100, 100, 1296, 750);

        this.cardlayout = new CardLayout();
        this.mapPanel = new MapPanel();
        getContentPane().setLayout(cardlayout);
        getContentPane().add(this.mapPanel, "Map");

        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    /**
     * Tells the MapFrame to show the map panel. Not necessary now, but could be useful in case we add more than one
     * panel to the map screen.
     */
    public void showMapPanel()
    {
        cardlayout.show(this.getContentPane(), "Map");
    }

    public void drawTile(int x, int y, Color c)
    {
        this.mapPanel.drawTile(x,y,c);
    }

    public void drawMap(Color[][] colorArray)
    {
        this.mapPanel.drawMap(colorArray);
    }

    public MapPanel getMapPanel()
    {
        return this.mapPanel;
    }


    /**
     * Test Main method for map rendering
     * @param args
     */
    public static void main(String[] args)
    {
        Random rand = new Random();
        MapFrame frame = new MapFrame();
        Color[][] colors = new Color[128][72];
        for(int i = 0; i < 128; i++)
        {
            for(int j = 0; j < 72; j++)
            {
                colors[i][j] = new Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255));
            }
        }
        frame.mapPanel.drawMap(colors);
        //frame.mapPanel.testMap();
    }

}
